package com.lld.im.service.message.controller;

import com.lld.im.common.ResponseVO;
import com.lld.im.common.enums.commond.GroupEventCommand;
import com.lld.im.common.enums.commond.MessageCommand;
import com.lld.im.common.model.message.CheckSendMessageReq;
import com.lld.im.service.group.service.GroupMessageServer;
import com.lld.im.service.message.server.P2PMessageServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1/message")
public class MessageRpcController {

    @Autowired
    private P2PMessageServer p2PMessageServer;

    @Autowired
    private GroupMessageServer groupMessageServer;


    @RequestMapping("/checkSend")
    public ResponseVO checkMsg(@RequestBody CheckSendMessageReq req){
        if(req.getCommand()== GroupEventCommand.MSG_GROUP.getCommand()){
            return groupMessageServer.checkGroupStatus(req.getAppId(),req.getFromId(),req.getGroupId());
        } else if (req.getCommand() == MessageCommand.MSG_P2P.getCommand()) {
            return p2PMessageServer.checkUserStatus(req.getAppId(), req.getFromId(), req.getToId());
        }
        return ResponseVO.errorResponse();
    }

}
